﻿package com._public._events
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	/**
	 * ...
	 * @author WZH(shch8.com)
	 * 事件异步发送
	 * InviteEventSen.sen(发送端，事件)
	 * 如：
	 * InviteEventSen.sen(this, new MenuEvent(MenuEvent.INIT));
	 * 相当于使用了this.dispatchEvent(new MenuEvent(MenuEvent.INIT));
	 */
	public class InviteEventSen 
	{
		
		private static var inviteEvent:InviteEventSen;
		public static function sen(eventDispatch:EventDispatcher,event:Event):void
		{
			if(!dispatch()){
			var timer:Timer = new Timer(10);
			timer.addEventListener(TimerEvent.TIMER, timerEvent);
			timer.start();
			}
			function timerEvent(e:TimerEvent):void
			{
					if(dispatch()){
						timer.removeEventListener(TimerEvent.TIMER, timerEvent);
						timer.stop();
						timer = null;
						}
			}
			function dispatch():Boolean
			{
				if (eventDispatch.hasEventListener(event.type)) {
					eventDispatch.dispatchEvent(event);
					return true;
					}
				return false;
			}
		}
	}
	
}